<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class School_Controller_ extends MY_Controller {
	
	private $mainMenuItems;
	
		
	/**
	 * 	Constructor
	 */
	function School_Controller() {
		
		parent::__construct();
		
		if ($this->ion_auth->is_group("school")) {
				
			$this->load->helpers(array('html'));
				
			$this->load->library(array('carabiner','template','fuelmenu','ion_auth','mylibrary'));
				
			$this->load->model('School_model');
				
			$this->lang->load('school');
				
			$this->carabiner->css('reset.css');
			//$this->carabiner->css('../templates/magicAdmin/css/reset.css');
			$this->carabiner->css('../templates/magicAdmin/css/styles.css');
			$this->carabiner->css('../templates/magicAdmin/css/grid.css');
			$this->carabiner->css('../templates/magicAdmin/css/theme-red.css');
			//$this->carabiner->css('reset.css');
			$this->carabiner->css('school.css');
			//$this->carabiner->css('school/grid.css');
			//$this->carabiner->css('school/theme-blue.css');
				
			$this->_iniTemplate();
			$this->_createMainMenuItems();
			$this->_setData();
		}
		else {		// not a school user? redirect ...
			redirect('Login/index');
		}
	}
	
	
	/**
	 * Create entries for main Navigation Menu
	 */
	private function _createMainMenuItems() {
			
		$this->mainMenuItems = array (
			'Sch/index'					=>	$this->lang->line('school.menu.main'),
			'Sch/SchOffers'				=>	$this->lang->line('school.menu.lnk1'),
			'Sch/SchExtras'				=>	'Extras',
			'School/schedules'			=>	$this->lang->line('school.menu.lnk2'),
			'Sch/SchMakeResevation'		=>	'Reservar',
			'School/reservations'		=>	$this->lang->line('school.menu.lnk3'),
			'School/classes'			=>	'Aulas',
			'Sch/SchTemplate'			=>	'Template'
			//'School/settings'			=>	'settings'
		);
	}
	
	
	/**
	 * Config the template library
	 */
	private function _iniTemplate() {
		$this->template->title('Radical Booking - Escola');
		$this->template->enable_parser(false);
		$this->template->set_layout('schLayout');
	}
	
	
	/**
	 * set global var's to be forward to all views
	 */
	private function _setData() {
	
		$school = $this->School_model->getUserInfo($this->ion_auth->get_user()->id);
		$user = $school;
	
		// format fields with data
		$school->created_on = date('Y-m-d H:i:s',$school->created_on);
		$school->last_login = date('Y-m-d H:i:s',$school->last_login);
	
		$this->template->set('school',$school);
		$this->template->set('user',$user);
		$this->template->set('mainMenuItems',$this->mainMenuItems);
	}
	
	
	protected function _activeLink($active = null) {
		$active = $this->uri->segment(2).$this->uri->slash_segment(3,'leading');
		return $active;
	}
}
